package com.fanxuankai.boot.monitor.autoconfigure;

import com.dingtalk.api.DingTalkClient;
import com.fanxuankai.boot.monitor.Notifier;
import com.fanxuankai.boot.monitor.WechatNotifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author fanxuankai
 */
@ConditionalOnClass({DingTalkClient.class, RestTemplate.class})
@ConditionalOnProperty(MonitorProperties.WECHAT_WEBHOOK)
public class WechatAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    public Notifier<?> notifier(MonitorProperties properties, RestTemplate restTemplate) {
        return new WechatNotifier(properties.getWechatWebhook(), restTemplate);
    }
}
